package com.burger.counter.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.burger.counter.beans.Burger;
import com.burger.counter.beans.BurgerBowl;
import com.burger.counter.beans.Starter;
import com.burger.counter.business.BurgerBowlBusiness;
import com.burger.counter.business.BurgerBusiness;
import com.burger.counter.business.StarterBusiness;

/**
 * Servlet implementation class BServlet
 */
public class BServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		// Getting data to starter Menu Option
		System.out.println("i am in Burger servlet");
		String burger = (String) request.getParameter("burger");
		System.out.println("Burger type selected..........:"+burger);	
		BurgerBusiness burgerBI = new BurgerBusiness();
		Burger burgerList[] =null;
		BurgerBowlBusiness burgerbowlBI = new BurgerBowlBusiness();
		//BurgerBowl burgerbowlList[] =null;
		HttpSession session = request.getSession(true);
		
		Integer regionId =(Integer)session.getAttribute("RegionId");
		try {
			if(burger.equals("NormalBurger")){
				burgerList = burgerBI.getBurgerDetails(regionId);}
			if(burger.equals("BurgerInBowl")){
				burgerList = burgerbowlBI.getBurgerDetails(regionId);}
		} 
		catch (Exception e) {
			e.printStackTrace();
		}
				
		session.setAttribute("burgerData", burgerList);
		for(int i=0;i<burgerList.length;i++)
		{
			System.out.println("ID:" + burgerList[i].getBurgerName());
			System.out.println("Name:" + burgerList[i].getBurgerWeight());
			
		}
		RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/burger.jsp");
		dispatcher.forward(request, response);
	}
}
